package 数组中第K个最大的元素;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.PriorityQueue;

public class Solution {
    public static int findKthLargest(int[] nums, int k) {
        PriorityQueue<Integer> pq = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer a, Integer b) {
                return a - b;
            }
        });

        for (int i = 0; i < nums.length; i++) {
            pq.add(nums[i]);
        }

        for(int j = 0 ; j < nums.length - k ; j++){
            pq.remove();
        }
        return pq.peek();

    }

}
